package hoang.hut.app.tool.raw;

import android.content.Context;
import android.media.MediaPlayer;

public class RawMusic {

	MediaPlayer mediaPlayer;

	/**
	 * Load dữ liệu
	 * 
	 * @param mContext
	 */
	public void loadMusic(Context mContext, int music) {
		mediaPlayer = MediaPlayer.create(mContext, music);
		mediaPlayer.setVolume(0.2f, 0.2f);
		mediaPlayer
				.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
					@Override
					public void onCompletion(MediaPlayer mp) {
						// Nhạc nền lặp đi lặp lại, play xong thì lại play lại
						play();
					}
				});
	}

	/**
	 * Play music
	 */
	public void play() {
		mediaPlayer.seekTo(0);
		mediaPlayer.start();
	}

	/**
	 * Pause music
	 */
	public void pause() {
		if (mediaPlayer.isPlaying())
			mediaPlayer.pause();
	}

	/**
	 * Resume music
	 */
	public void resume() {
		if (!mediaPlayer.isPlaying())
			mediaPlayer.start();
	}

	/**
	 * Xóa bỏ
	 */
	public void release() {
		mediaPlayer.release();
	}
}
